﻿@using Entidades.Sistema.Base
@using System.Collections.ObjectModel;

@{
    Html.EnableClientValidation();
    Html.EnableUnobtrusiveJavaScript();

    var grid = Html.DevExpress().GridView(
        settings =>
        {
            settings.Name = "gvEditing";
            settings.KeyFieldName = "IdZona";
            settings.CallbackRouteValues = new { Controller = "Zona", Action = "EditZonaPartial" };

            settings.Columns.Add(column =>
            {
                column.Caption = "#";
                column.SetDataItemTemplateContent(c =>
                {
                    ViewContext.Writer.Write(
                        Html.ActionLink("Editar", "EditZonaUpdatePartial", new { IdZona = DataBinder.Eval(c.DataItem, "IdZona") }) + "&nbsp;" +
                        Html.ActionLink("Eliminar", "EditZonaDeletePartial", new { IdZona = DataBinder.Eval(c.DataItem, "IdZona") },
                            new { onclick = "return confirm('Realmente quiere elimnar la Zona?')" })
                    );
                });
                column.SetHeaderTemplateContent(c =>
                {
                    ViewContext.Writer.Write(
                        Html.ActionLink("Nuevo", "EditZonaUpdatePartial", new { IdZona = -1 }).ToHtmlString()
                    );
                });
                column.Settings.AllowDragDrop = DefaultBoolean.False;
                column.Settings.AllowSort = DefaultBoolean.False;
                column.Width = 70;
            });
            
            
            
            settings.SettingsBehavior.ConfirmDelete = true;
            settings.SettingsPopup.EditForm.Width = 600;
            settings.SettingsPopup.EditForm.HorizontalAlign = PopupHorizontalAlign.Center;
            settings.SettingsPopup.EditForm.VerticalAlign = PopupVerticalAlign.WindowCenter;
            settings.SettingsPager.FirstPageButton.Visible = true;
            settings.SettingsPager.LastPageButton.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Visible = true;
            settings.SettingsPager.PageSizeItemSettings.Items = new string[] { "10", "20", "50" };
            
            
            settings.Settings.ShowFilterRow = true;
            settings.Settings.ShowFilterRowMenu = true;
            settings.CommandColumn.Visible = true;
            settings.CommandColumn.ShowClearFilterButton = true;
            
            settings.Width = System.Web.UI.WebControls.Unit.Percentage(100);

            settings.Columns.Add("IdZona");
            settings.Columns.Add("Nombre");
            settings.Columns.Add(
                column =>
                {
                    column.FieldName = "Empleado.NombreApellido";
                    column.Caption = "Empleado";

                    column.ColumnType = MVCxGridViewColumnType.ComboBox;
                    var comboBoxProperties = column.PropertiesEdit as ComboBoxProperties;
                    comboBoxProperties.DataSource = ViewBag.Empleado;
                    comboBoxProperties.TextField = "NombreApellido";
                    comboBoxProperties.ValueField = "IdEmpleado";
                    comboBoxProperties.ValueType = typeof(int);
                    comboBoxProperties.DropDownStyle = DropDownStyle.DropDown;
                });
        });   

    if (ViewData["EditError"] != null){
        grid.SetEditErrorText((string)ViewData["EditError"]);
    }
}

@grid.Bind(Model).GetHtml()





